package com.huawei.M01.iterator;

import java.util.Scanner;

/**
 * 01背包问题
 *
 * @author 111
 */
public class Knapsacks01 {
    private static final int N = 510;
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] firstLine = scanner.nextLine().split(" ");
        int n = Integer.parseInt(firstLine[0]);
        int v = Integer.parseInt(firstLine[1]);
        int[][] dp = new int[N][N];
        int[] value = new int[N];
        int[] weight = new int[N];
        for (int i = 1; i <= n; i++) {
            String[] line = scanner.nextLine().split(" ");
            weight[i] = Integer.parseInt(line[0]);
            value[i] = Integer.parseInt(line[1]);
        }

        // 动态规划
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= v; j++) {
                // 剩余体积过小无法放入当前苹果
                if (j < weight[i]) {
                    dp[i][j] = dp[i - 1][j];
                }else {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - weight[i]] + value[i]);
                }
            }
        }
        System.out.println(dp[n][v]);
    }
}
